﻿using UnityEngine;
using System.Collections;

public class bullet:MonoBehaviour {

    private const string Player = "Player";
    private const string Enemy = "Enemy";

    [SerializeField]
    private float speed = 10f;

    private float direction = 1f;

    [SerializeField]
    private Transform player;

    private void Awake() {

        player = GameObject.Find(Player).transform;

        //Destroy(gameObject,2);
        direction = player.localScale.x;
    }

    private void Update() {

        transform.position = new Vector3(transform.position.x + direction * speed * Time.deltaTime
            ,transform.position.y
            ,transform.position.z);

    }

    private void OnTriggerEnter2D(Collider2D col) {

        Debug.Log(col.tag);

        if (col.tag == Player)
        {

        }
        else if (col.tag == Enemy)
        {

            体力 体力变量 = col.gameObject.GetComponent<体力>();

            体力变量.攻击监听(20f);

            //Destroy(col.gameObject);
        }
        else {
            Destroy(gameObject);
        }


    }

}
